package com.geeka.d12.tcpmulti;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class ServerThread extends Thread {
    private Socket socket;

    public ServerThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //获取客户端 的IP和端口
        String cname = socket.getInetAddress() + " " + socket.getPort();
        try {
            InputStream ips = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(ips));
            String s = null;

            while ((s = br.readLine()) != null) {
                System.out.println(cname+":"+s);
            }
        } catch (IOException e) {
            System.out.println(" socket异常: " + e.getMessage());
            e.printStackTrace();
        }
    }

}
